<template>
    <el-row class="menu_page">
        <el-col>
            <el-menu
                    mode="vertical"
                    background-color="#324057"
                    text-color="#fff"
                    active-text-color="#409eff"
                    class="el-menu-vertical-demo"
                    unique-opened
                    >
                <router-link to="/index">
                    <el-menu-item index="0">
                        <i class="fa fa-margin el-icon-menu"></i>
                        <span slot="title">首页</span>
                    </el-menu-item>
                </router-link>
                <template  v-for="item in items" >
                    <el-submenu v-if="item.author<user.role" :index="item.path" :key="item.path">
                        <template slot="title">
                            <i :class="'fa fa-margin '+item.icon"></i>
                            <span slot="title">{{item.name}}</span>
                        </template>
                        <router-link v-for="(citem,cindex) in item.children"
                                     :to="citem.path" :key="cindex">
                            <el-menu-item
                                    :index='citem.path'>
                                <span slot="title">{{citem.name}}</span>
                            </el-menu-item>
                        </router-link>
                    </el-submenu>

                </template>
            </el-menu>
        </el-col>
    </el-row>
</template>
<script>
    export default {
        name: "leftmenu",
        computed:{
            user(){
                return this.$store.getters.user;
            }
        },
        data() {
            return {
                items: [
                    {
                        icon: "el-icon-edit",
                        name: "报账单",
                        path: "reported",
                        author:'0',
                        children: [{ path: "/reported/all", name: "报账单总览" },
                                   { path: "/reported/list", name: "报账单列表" },
                                   { path: "/reported/add", name: "新增报账单" }]
                    },
                    {
                        icon: "el-icon-edit-outline",
                        name: "维修备件",
                        path: "repair",
                        author:'4',
                        children: [ { path: "/repair/list", name: "维修备件列表" },
                                    { path: "/repair/add", name: "新增维修备件" },
                                    { path: "/repair/partadd", name: "维修备件添加记录" },
                                    { path: "/repair/partuse", name: "维修备件使用情况" }
                        ]
                    },

                    {
                        icon: "el-icon-more",
                        name: "故障类别",
                        path: "fault",
                        author:'8',
                        children: [{ path: "/fault/list", name: "故障类别列表" },
                            { path: "/fault/sort", name: "新增故障类别" }
                          ]
                    },
                    {
                        icon: "fa-bars",
                        name: "维修分类",
                        path: "columns",
                        author:'8',
                        children: [{ path: "/columns/list", name: "维修分类列表" },
                            { path: "/columns/add", name: "新增维修分类" }
                        ]
                    },
                    {
                        icon: "fa fa-user",
                        name: "维修人员",
                        path: "user",
                        author:'8',
                        children: [{ path: "/user/list", name: "维修人员列表" },
                            { path: "/user/add", name: "新增维修人员" }
                        ]
                    },
                    {
                        icon: "fa-location-arrow",
                        name: "维修区域",
                        path: "location",
                        author:'8',
                        children: [{ path: "/location/list", name: "维修区域列表" },
                            { path: "/location/add", name: "新增维修区域" }
                        ]
                    },
                ]
            };
        }
    };
</script>
<style scoped>
    .menu_page {
        position: fixed;
        top: 71px;
        left: 0;
        min-height: 100%;
        background-color: #324057;
        z-index: 99;

    }
    .el-menu {
        border: none;
    }
    .fa-margin {
        margin-right: 5px;
    }
    .el-menu-vertical-demo:not(.el-menu--collapse) {
        width: 180px;
        min-height: 400px;
    }
    .el-menu-vertical-demo {
        width: 35px;
    }
    .el-submenu .el-menu-item {
        min-width: 180px;
    }

    .hiddenDropdown,
    .hiddenDropname {
        display: none;
    }
    a {
        text-decoration: none;
    }
</style>
